package scaladuct.asm

import org.objectweb.asm.util.TraceClassVisitor
import org.objectweb.asm.ClassReader
import java.io.{InputStream, PrintWriter, ByteArrayInputStream}

/**
 * <p>
 * Created by IntelliJ IDEA.
 * User: zslajchrt
 * Date: Aug 16, 2010
 * Time: 11:34:06 AM
 */

object ClassStructureWriter {

  implicit val defaultPrintWriter: PrintWriter = new PrintWriter(System.out)

  def apply(byteCode: Array[Byte])(implicit writer: PrintWriter) {
    apply(new ByteArrayInputStream(byteCode))(writer)
  }

  def apply(byteCodeStream: InputStream)(implicit writer: PrintWriter) {
    val bcReader: ClassReader = new ClassReader(byteCodeStream)
    bcReader.accept(new TraceClassVisitor(writer), 0)
  }
}

